<?php

namespace app\api\controller\kuyou\applet;

use app\common\controller\Api;
use app\api\model\kuyou\applet\Systems as Systems;
/**
 * 系统配置接口
 */
class Config extends Api
{
    protected $noNeedRight = '*';
    protected $noNeedLogin = ['getdetail'];

    /**
     * 获取系统配置详情
     * @ApiMethod (POST)
     * @param int $id 系统配置ID
     */
    public function getdetail()
    {
        if ($this->request->isPost()) {
            $name = $this->request->post('name');
            $result = Systems::getDetail($name);
            $this->success('查询成功',$result,200);
        }else{
            $this->error('请求方式错误','',250);
        }
    }

    /**
     * 添加系统配置
     * @ApiMethod (POST)
     * @param array $detail 系统配置数据
     */
    public function adddetail()
    {
        if ($this->request->isPost()) {
            $detail = $this->request->post();
            foreach ($detail as $k=>$v){
                $detail[$k] = is_array($v)?$v:($v);
            }
            $ret = Systems::addDetail($detail);
            if($ret['status']==200){
                $this->success('添加成功',$ret['msg'],200);
            }else{
                $this->error($ret['msg'],'',$ret['status']);
            }
        }else{
            $this->error('请求方式错误','',250);
        }
    }

    /**
     * 更新系统配置
     * @ApiMethod (POST)
     * @param array $detail 系统配置数据
     */
    public function editdetail()
    {
        if ($this->request->isPost()) {
            $detail = $this->request->post();
            foreach ($detail as $k=>$v){
                $detail[$k] = is_array($v)?$v:($v);
            }
            $ret = Systems::editDetail($detail);
            if($ret['status']==200){
                $this->success('更新成功','',200);
            }else{
                $this->error($ret['msg'],'',$ret['status']);
            }
        }else{
            $this->error('请求方式错误','',250);
        }
    }
}
